package com.safeluck.scannerqcr.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.safeluck.scannerqcr.R;
import com.safeluck.scannerqcr.bean.Chat;
import com.safeluck.scannerqcr.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * ScannerQCR
 * Created by lzw on 2017/12/6. 17:11:59
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

public class ChatDetailAdapter extends RecyclerView.Adapter<ChatDetailAdapter.DetailHoder> {


    private static final int LEFT = 1;
    private static final int RIGHT = 2;
    private LayoutInflater mInflater ;
    private List<Chat> chats = new ArrayList<>();
    private OnItemClickListener mListener;

    @Override
    public DetailHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;

            view= mInflater.inflate(R.layout.chat_detail_item_left,parent,false);

        final DetailHoder detailHoder = new DetailHoder(view);
        detailHoder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null){
                    mListener.onItemClick(detailHoder.getAdapterPosition(),detailHoder.itemView,
                            detailHoder);
                }
            }
        });
        return detailHoder;
    }

    @Override
    public void onBindViewHolder(DetailHoder holder, int position) {
        Chat chat = chats.get(position);
        holder.tv_msg.setText(chat.message);
    }


    public ChatDetailAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getItemCount() {
        return chats.size();
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    public void setDatas(Chat datas) {
        this.chats.add(datas);
    }

    class DetailHoder extends RecyclerView.ViewHolder{

        private TextView tv_msg;
        private ImageView iv;

        public DetailHoder(View itemView) {
            super(itemView);
            tv_msg = itemView.findViewById(R.id.tv_content_msg);
        }
    }
}
